package com.tetris.common;

import javax.swing.ImageIcon;

/**
 * 文件工具类
 * @author jerry
 *
 */
public class FileUtil {
	
	private static String iconRoot = "imgs/";
		
	/**
	 * 图片数组
	 */
	private static ImageIcon[] icons;
	
	private static int iconsNum = 5;

	/**
	 * 获得序号为num的图片
	 * @return
	 */
	public static ImageIcon getIcon(int index){
		initIcons(iconsNum);
		return icons[index];
	}
	
	/**
	 * 初始化图片数组
	 */
	private static void initIcons(int num){
		if(icons != null)
			return;
		icons = new ImageIcon[num];
		for(int i=0;i<num;i++){
			String path = iconRoot + i + ".jpg";
			icons[i] = new ImageIcon(path);
		}
	}
}
